package cn.ekuma.security.impl;

import java.util.ArrayList;
import java.util.List;

import cn.ekuma.security.bean.I_GroupPermission;
import cn.ekuma.security.bean.I_Permission;

public class GroupPermission implements I_GroupPermission {
	ArrayList<I_GroupPermission> permissions;
	I_GroupPermission parent;
	I_Permission permission;
	int groupLevel=0;
	
	public GroupPermission(I_GroupPermission parent,I_Permission permission) {
		super();
		this.parent = parent;
		permissions=new ArrayList();
		this.permission=permission;
	}
	
	public GroupPermission(I_GroupPermission parent2,I_Permission permission,int level) {
		super();
		this.parent = parent2;
		permissions=new ArrayList();
		this.permission=permission;
		this.groupLevel=level;
	}

	@Override
	public void addChildPermission(I_GroupPermission p) {
		permissions.add(p);
	}

	@Override
	public I_GroupPermission getParent() {
		return parent;
	}

	@Override
	public List<I_GroupPermission> getChilds() {
		return permissions;
	}

	@Override
	public int getLevel() {
		return groupLevel;
	}

	@Override
	public I_GroupPermission getChildById(int id) {
		for(I_GroupPermission p:permissions)
			if(p.getPermission().getId()==id)
				return p;
		return null;
	}

	@Override
	public I_Permission getPermission() {
		return permission;
	}

	@Override
	public void setPermission(I_Permission p) {
		this.permission=p;	
	}

}
